<?php
/*
 * tbk controller 2012.6.28 tbk.php
 */

class tbk extends CI_Controller {
	function __construct() {
		parent::__construct ();
		$this->load->helper ( 'url' );
		session_start();
		//加载淘客功能类库
		$this->load->library ( array (
				'TopClient',
				'Convert',
				'LtLogger',
				'RequestCheckUtil',
				'Detail',
				'Coupon',
				'shops',
				'commonClass',
				'pagination',
				'table' ,
				'itemsget'
		) );
	}
	public function index() {
		$lang ['error'] = '';
		$uid = commonClass::Listion_user ();
		if ($uid) {
			$lang ['uid'] = $_SESSION ['uid'];
			$lang ['usermail'] = $_SESSION ['usermail'];
		}
		$_SESSION ['ip'] = $this->input->ip_address ();
		$word = $this->_lang ['hot'];
		
		$lang ["goods_hot"] = $this->init ( $word );

		$lang ["modle"] = "index"; // 导航栏标记
		                           
		// 获取商品分类导航栏
		$sql = "SELECT id,`name`,f_id FROM `tb_nav` where f_id = 0 AND is_show =1 AND is_del=0 ORDER BY `order`";
		$nav = $this->m_tbk->tbk_query ( $sql ); // 一级导航
		foreach ( $nav as $key => $v ) { // 二级导航
			$sql = 'SELECT id,`name`,f_id FROM `tb_nav` where f_id = ' . $v->id . ' AND is_show=1 AND is_del=0 ORDER BY `order`';
			$nav [$key]->c_nav = $this->m_tbk->tbk_query ( $sql );
		}
		$lang ["nav"] = $nav;
		// var_dump($nav);die;
		$lang ["title"] = $word;
		$this->load->view ( 'v_tbk', $lang );
	}
	/*
	 * report page
	 */
	
	public function get_info() {
		//获取单品搜索统计数据
		$val = $this->m_tbk->get_info ();
		$result = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /></head><body>";
		$result .= "<table><tr><th>ID</th><th>uid</th><th>num_iid</th><th>title</th><th>nick</th><th>price</th><th>commission</th><th>click</th><th>addtime</th></tr>";
		foreach ( $val as $key ) {
			$result .= "<tr><td>" . $key->id . "</td><td>" . $key->uid . "</td><td>" . $key->num_iid . "</td><td>" . $key->title . "</td><td>" . $key->nick . "</td><td>" . $key->price . "</td><td>" . $key->commission . "</td><td>" . $key->click . "</td><td>" . date ( 'Y-m-d', $key->add_time ) . "</td></tr>";
		}
		$result .= "</table></body></html>";
		echo $result;
	}
	
	/*
	 * the function translate ip address to longint
	 */
	private function ip2int() {
		//获取ip地址的整形字符窜
		$sIP = $this->input->ip_address ();
		$aIP = explode ( '.', $sIP );
		$IP = ($aIP [0] << 24) | ($aIP [1] << 16) | ($aIP [2] << 8) | $aIP [3];
		if ($IP < 0) {
			$IP += 4294967296;
		}
		return $IP;
	}
	// get the num_iid or keyword from the input from user
	private function get_num_iid($url) {
		$res = parse_url ( $url );
		if (isset ( $res ['query'] )) {
			$val = parse_str ( $res ['query'] );
			$num = $id;
		} else {
			if (preg_match ( '/^(\d)*$/', $res ['path'] )) {
				$num = $url;
			} else {
				if (preg_match ( '/[zq]/', $res ['path'] )) {
					$keyword = explode ( 'zq', $url );
					$word = $keyword [1];
					$c = new TopClient ();
					$c->appkey = APPKEY;
					$c->secretKey = SECRETKEY;
					$req = new Coupon ();
					//如果是会员将会员id带上
					if (isset ( $_SESSION ['uid'] )) {
						$req->setOuterCode ($_SESSION ['uid']);
					}
					$req->setPid ( "17750613" );
					$req->setKeyword ( $word );
					$req->setFields ( "num_iid,nick,price,click_url,pic_url,coupon_rate,coupon_price,coupon_start_time,coupon_end_time,commission_rate,shop_type" );
					$resp = $c->execute ( $req );
					$res = $c->get_object_vars_final ( $resp );
					$val = $res ['taobaoke_items'] ['taobaoke_item'];
					if (empty ( $res )) {
						$result ['error'] = 1;
						$result ['msg'] = $this->_lang ['tbk_not_in'];
					} else {
						$result ['html'] = "<table><thead><tr><th>" . $this->_lang ['pic'] . "</th><th>" . $this->_lang ['price'] . "</th><th>" . $this->_lang ['coupon_rate'] . "</th><th>" . $this->_lang ['coupon_price'] . "</th><th>" . $this->_lang ['coupon_end_time'] . "</th><th>" . $this->_lang ['commission_rate'] . "</th><th>" . $this->_lang ['commission'] . "</th><th>" . $this->_lang ['nick'] . "</th></tr></thead>";
						foreach ( $val as $key ) {
							$result ['html'] .= "<tbody><tr>";
							$result ['html'] .= "<td><a href=" . $key ['click_url'] . " target='_blank' ><img src=" . $key ['pic_url'] . " width=100 height=100 ></a></td>";
							$result ['html'] .= "<td>" . $key ['price'] . "</td>";
							$result ['html'] .= "<td><font color='red'>" . round ( $key ['coupon_rate'] * 0.001, 1 ) . $this->_lang ['coupon'] . "</font></td>";
							$result ['html'] .= "<td><font color='red'>" . $key ['coupon_price'] . "</font></td>";
							$result ['html'] .= "<td>" . $key ['coupon_end_time'] . "</td>";
							$result ['html'] .= "<td>" . $key ['commission_rate'] * 0.005 . "%</td>";
							$result ['html'] .= "<td>" . round ( $key ['coupon_price'] * $key ['commission_rate'] * 0.00005, 2 ) . "</td>";
							$result ['html'] .= "<td>" . $key ['nick'] . "</td></tr></tbody>";
						}
						$result ['html'] .= "</table>";
						$result ['html'] .= '<a class="button" onclick="goods(\'' . $word . '\',1)" >' . $this->_lang ['prepage'] . '</a>';
						$result ['html'] .= '<a class="button" onclick="goods(\'' . $word . '\',2)" >' . $this->_lang ['nextpage'] . '</a>';
						$result ['error'] = 0;
					}
				} else {
					$c = new TopClient;
					$c->appkey = APPKEY;
					$c->secretKey = SECRETKEY;
					$req = new ItemsGet;
					$req->setFields("num_iid,title,nick,price,click_url,commission,commission_rate,item_location");
					$req->setPid(17750613);
					//如果是会员将会员id带上
					if (isset ( $_SESSION ['uid'] )) {
						$req->setOuterCode ($_SESSION ['uid']);
					}
					$req->setKeyword($url);
					$resp = $c->execute($req);
					$res = $c->get_object_vars_final ( $resp );
					$val = $res ['taobaoke_items'] ['taobaoke_item'];
				
					if (empty ( $res )) {
						$result ['error'] = 1;
						$result ['msg'] = $this->_lang ['tbk_not_in'];
					} else {
						if($val[1]){
							foreach($val as $v){
								$location = explode ( ' ', $v ['item_location'] );
								@$v ['province'] = $location [0];
								@$v ['city'] = $location [1];
								unset ( $v ['item_location'] );
								$area = empty ( $v ['city'] ) ? $v ['province'] : $v ['city'];
								
								//获取折扣数据
								$coupon = $this->get_coupon_price ( $v ['num_iid'], $v ['title'], $area );
								
								if (! empty ( $coupon )) {
									$v ['coupon_price'] = $coupon ['coupon_price'];
									$v ['coupon_rate'] = round ( $coupon ['coupon_rate'] / 1000, 1 );
								}
								if (isset ( $_SESSION ['uid'] )) {
									$v ['uid'] = $_SESSION ['uid'];
								} else {
									$v ['uid'] = $this->ip2int ();
								}
								$v ['add_time'] = time ();
								$real_price = empty ( $v ['coupon_price'] ) ? $v ['price'] : $v ['coupon_price'];
								
								//将商品数据入库，方便统计
								//$this->m_tbk->click ( $val ['num_iid'] );
								//$this->m_tbk->add_good_info ( $val );
								
								$result ['html'] = "<table><tr><th>" . $this->_lang ['price'] . "</th>";
								if (@$v ['coupon_price'] == '') {
									$result ['html'] .= "<th>" . $this->_lang ['coupon_price'] . "</th>";
								} else {
									$result ['html'] .= "<th>" . $this->_lang ['coupon_price'] . "</th><th>" . $this->_lang ['coupon_rate'] . "</th>";
								}
								$result ['html'] .= "<th>" . $this->_lang ['commission'] . "</th><th>" . $this->_lang ['commission_rate'] . "</th><th>" . $this->_lang ['nick'] . "</th><th>" . $this->_lang ['method'] . "</th></tr>";
								$result ['html'] .= "<tr><td>" . $v ['price'] . $this->_lang ['yuan'] . "</td>";
								if (@$v ['coupon_price'] == '') {
									$result ['html'] .= "<td><font color='red'>" . $this->_lang ['vip'] . "</font></td>";
								} else {
									$result ['html'] .= "<td><font color='red'>" . $v ['coupon_price'] . $this->_lang ['yuan'] . "</font></td><td><font color='red'>" . $v ['coupon_rate'] . $this->_lang ['coupon'] . "</font></td>";
								}
								$result ['html'] .= "<td>" . round ( $v ['commission_rate'] / 20000 * $real_price, 1 ) . $this->_lang ['yuan'] . "</td><td>" . $v ['commission_rate'] / 200 . "%</td><td>" . $v ['nick'] . "</td><td><a href=" . $v ['click_url'] . " class='button' target='_blank' >" . $this->_lang ['click'] . "</a></td></tr></table>";
								$result ['error'] = 0;
							}
						}else{
							$location = explode ( ' ', $val ['item_location'] );
							@$val ['province'] = $location [0];
							@$val ['city'] = $location [1];
							unset ( $val ['item_location'] );
							$area = empty ( $val ['city'] ) ? $val ['province'] : $val ['city'];

							//获取折扣数据
							$coupon = $this->get_coupon_price ( $val ['num_iid'], $val ['title'], $area );

							if (! empty ( $coupon )) {
								$val ['coupon_price'] = $coupon ['coupon_price'];
								$val ['coupon_rate'] = round ( $coupon ['coupon_rate'] / 1000, 1 );
							}
							if (isset ( $_SESSION ['uid'] )) {
								$val ['uid'] = $_SESSION ['uid'];
							} else {
								$val ['uid'] = $this->ip2int ();
							}
							$val ['add_time'] = time ();
							$real_price = empty ( $val ['coupon_price'] ) ? $val ['price'] : $val ['coupon_price'];

							//将商品数据入库，方便统计
							//$this->m_tbk->click ( $val ['num_iid'] );
							//$this->m_tbk->add_good_info ( $val );

							$result ['html'] = "<table><tr><th>" . $this->_lang ['price'] . "</th>";
							if (@$val ['coupon_price'] == '') {
								$result ['html'] .= "<th>" . $this->_lang ['coupon_price'] . "</th>";
							} else {
								$result ['html'] .= "<th>" . $this->_lang ['coupon_price'] . "</th><th>" . $this->_lang ['coupon_rate'] . "</th>";
							}
							$result ['html'] .= "<th>" . $this->_lang ['commission'] . "</th><th>" . $this->_lang ['commission_rate'] . "</th><th>" . $this->_lang ['nick'] . "</th><th>" . $this->_lang ['method'] . "</th></tr>";
							$result ['html'] .= "<tr><td>" . $val ['price'] . $this->_lang ['yuan'] . "</td>";
							if (@$val ['coupon_price'] == '') {
								$result ['html'] .= "<td><font color='red'>" . $this->_lang ['vip'] . "</font></td>";
							} else {
								$result ['html'] .= "<td><font color='red'>" . $val ['coupon_price'] . $this->_lang ['yuan'] . "</font></td><td><font color='red'>" . $val ['coupon_rate'] . $this->_lang ['coupon'] . "</font></td>";
							}
							$result ['html'] .= "<td>" . round ( $val ['commission_rate'] / 20000 * $real_price, 1 ) . $this->_lang ['yuan'] . "</td><td>" . $val ['commission_rate'] / 200 . "%</td><td>" . $val ['nick'] . "</td><td><a href=" . $val ['click_url'] . " class='button' target='_blank' >" . $this->_lang ['click'] . "</a></td></tr></table>";
							$result ['error'] = 0;
						}
					}
				}
				echo json_encode ( $result );
				exit ();
			}
		}
		return $num;
	}
	
	// single goods search controller function
	public function get_goods() {
		//单品搜索功能
		$url = $this->input->post ( 'search' );
		
		if (empty ( $url )) {
			$result ['error'] = 1;
			$result ['msg'] = $this->_lang ['tbk_post_nothing'];
		} else {
			//获取num_iid
			$num = $this->get_num_iid ( $url );
			$c = new TopClient ();
			$c->appkey = APPKEY;
			$c->secretKey = SECRETKEY;
			$req = new Convert ();
			$req->setFields ( "num_iid,title,nick,price,click_url,commission,commission_rate,item_location" );
		//	$req->setFields ( "num_iid,title,volume,nick,price,item_location,click_url,pic_url,coupon_rate,coupon_price,coupon_start_time,coupon_end_time,commission_rate,commission,shop_type");
			if ($_SESSION ['uid'] !="") {
				$req->setOuterCode ( $_SESSION ['uid']);
			}else{
				$req->setOuterCode ( $_COOKIE['uid']);
			}
			$req->setNumIids ( $num );
			$req->setPid ( 17750613 );
			$resp = $c->execute ( $req );
			$res = $c->get_object_vars_final ( $resp );
			if (@$res ['total_results'] == 0) {
				$result ['error'] = 1;
				$result ['msg'] = $this->_lang ['tbk_not_promote'];
			} else {
				$val = $res ['taobaoke_items'] ['taobaoke_item'];
				$location = explode ( ' ', $val ['item_location'] );
				@$val ['province'] = $location [0];
				@$val ['city'] = $location [1];
				unset ( $val ['item_location'] );
				$area = empty ( $val ['city'] ) ? $val ['province'] : $val ['city'];
				
				//获取折扣数据
				$coupon = $this->get_coupon_price ( $val ['num_iid'], $val ['title'], $area );
				
				if (! empty ( $coupon )) {
					$val ['coupon_price'] = $coupon ['coupon_price'];
					$val ['coupon_rate'] = round ( $coupon ['coupon_rate'] / 1000, 1 );
				}
				if (isset ( $_SESSION ['uid'] )) {
					$val ['uid'] = $_SESSION ['uid'];
				} else {
					$val ['uid'] = $this->ip2int ();
				}
				$val ['add_time'] = time ();
				$real_price = empty ( $val ['coupon_price'] ) ? $val ['price'] : $val ['coupon_price'];
				
				//将商品数据入库，方便统计
				$this->m_tbk->click ( $val ['num_iid'] );
				$this->m_tbk->add_good_info ( $val );
				
				$result ['html'] = "<table style='width:	60%'><tr><th>" . $this->_lang ['price'] . "</th>";
				if (@$val ['coupon_price'] == '') {
					$result ['html'] .= "<th>" . $this->_lang ['coupon_price'] . "</th>";
				} else {
					$result ['html'] .= "<th>" . $this->_lang ['coupon_price'] . "</th><th>" . $this->_lang ['coupon_rate'] . "</th>";
				}
				$result ['html'] .= "<th>" . $this->_lang ['commission'] . "</th><th>" . $this->_lang ['commission_rate'] . "</th><th>" . $this->_lang ['nick'] . "</th><th>" . $this->_lang ['method'] . "</th></tr>";
				$result ['html'] .= "<tr><td>" . $val ['price'] . $this->_lang ['yuan'] . "</td>";
				if (@$val ['coupon_price'] == '') {
					$result ['html'] .= "<td><font color='red'>" . $this->_lang ['vip'] . "</font></td>";
				} else {
					$result ['html'] .= "<td><font color='red'>" . $val ['coupon_price'] . $this->_lang ['yuan'] . "</font></td><td><font color='red'>" . $val ['coupon_rate'] . $this->_lang ['coupon'] . "</font></td>";
				}
				$result ['html'] .= "<td><strong style='color:red;font-size:20px'>" . round ( $val ['commission_rate'] / 20000 * $real_price, 1 ) . $this->_lang ['yuan'] . "</strong></td><td>" . $val ['commission_rate'] / 200 . "%</td><td>" . $val ['nick'] . "</td><td><a data-href=" . $val ['click_url'] . " class='button' id='goto_buy' data-url='".base_url('index.php/tbk/is_load')."' target='_blank' >" . $this->_lang ['click'] . "</a></td></tr></table>";
				$result ['error'] = 0;
			}
		}
		echo json_encode ( $result );
	}
	
	// shop search controller function
	public function shop_search() {
		$keyword = $this->input->post ( 'shop', TRUE );
		if (empty ( $keyword )) {
			$result ['error'] = 1;
			$result ['msg'] = $this->_lang ['c_error_search_data_empty'];
		} else {
			$c = new TopClient ();
			$c->appkey = APPKEY;
			$c->secretKey = SECRETKEY;
			$req = new Shops ();
			$req->setFields ( 'user_id,shop_title,click_url,commission_rate,seller_credit,shop_type,total_auction,auction_count' );
			$req->setKeyword ( $keyword );
			$req->setPid ( 17750613 );
			if (isset ( $_SESSION ['uid'] )) {
				$req->setOuterCode ($_SESSION ['uid']);
			}
			$resp = $c->execute ( $req );
			$res = $c->get_object_vars_final ( $resp );
			$shops = @$res ['taobaoke_shops'] ['taobaoke_shop'];
			if (empty ( $shops )) {
				$result ['error'] = 1;
				$result ['msg'] = $this->_lang ['s_no_shop'];
			} else {
				//如返回多个店铺信息
				if (isset ( $shops [1] )) {
					$result ['error'] = 0;
					$result ['html'] = "<table><tr><th>" . $this->_lang ['s_nick'] . "</th><th>" . $this->_lang ['s_title'] . "</th><th>" . $this->_lang ['s_credit'] . "</th><th>" . $this->_lang ['s_type'] . "</th><th>" . $this->_lang ['s_auction_count'] . "</th><th>" . $this->_lang ['method'] . "</th></tr>";
					foreach ( $shops as $s ) {
						$result ['html'] .= "<tr><td>" . $s ['user_id'] . "</td><td>" . $s ['shop_title'] . "</td><td><img src='" . base_url ( 'images/' ) . "/" . $s ['seller_credit'] . ".gif' /></td>";
						if ($s ['shop_type'] == 'B') {
							$result ['html'] .= "<td>" . $this->_lang ['s_mall'] . "</td>";
						} else {
							$result ['html'] .= "<td>" . $this->_lang ['s_taobao'] . "</td>";
						}
						$result ['html'] .= "<td>" . $s ['auction_count'] . "</td><td><a href='" . $s ['click_url'] . "' class='button' target='_blank' >" . $this->_lang ['click'] . "</a></td></tr>";
					}
					$result ['html'] .= "</table>";
					$result ['error'] = 0;
				} else {
					//单个店铺返回信息
					$result ['html'] = "<table><tr><th>" . $this->_lang ['s_nick'] . "</th><th>" . $this->_lang ['s_title'] . "</th><th>" . $this->_lang ['s_credit'] . "</th><th>" . $this->_lang ['s_type'] . "</th><th>" . $this->_lang ['s_auction_count'] . "</th><th>" . $this->_lang ['method'] . "</th></tr>";
					$result ['html'] .= "<tr><td>" . $shops ['user_id'] . "</td><td>" . $shops ['shop_title'] . "</td><td><img src='" . base_url ( 'images/' ) . "/" . $shops ['seller_credit'] . ".gif' /></td>";
					if ($shops ['shop_type'] == 'B') {
						$result ['html'] .= "<td>" . $this->_lang ['s_mall'] . "</td>";
					} else {
						$result ['html'] .= "<td>" . $this->_lang ['s_taobao'] . "</td>";
					}
					$result ['html'] .= "<td>" . $shops ['auction_count'] . "</td><td><a href='" . $shops ['click_url'] . "' class='button' target='_blank' >" . $this->_lang ['click'] . "</a></td></tr></table>";
					$result ['error'] = 0;
				}
			
			}
		}
		echo json_encode ( $result );
		exit ();
	}
	
	// get coupon price function
	private function get_coupon_price($num_iid, $title, $area) {
		//获取折扣信息
		$c = new TopClient ();
		$c->appkey = APPKEY;
		$c->secretKey = SECRETKEY;
		$req = new Coupon ();
		$req->setPid ( 17750613 );
		$req->setKeyword ( $title );
		$req->setArea ( $area );
		$req->setFields ( "num_iid,coupon_rate,coupon_price" );
		$resp = $c->execute ( $req );
		$res = $c->get_object_vars_final ( $resp );
		
		$val = @$res ['taobaoke_items'] ['taobaoke_item'];
		$coupon = array ();
		if (empty ( $val )) {
			return $coupon;
		} else {
			//单个商品返回折扣信息
			if (isset ( $val ['num_iid'] )) {
				unset ( $val ['num_iid'] );
				$coupon = $val;
			} else {
				//多个商品返回折扣信息
				foreach ( $val as $key ) {
					if ($num_iid == $key ['num_iid']) {
						unset ( $key ['num_iid'] );
						$coupon = $key;
						break;
					}
				}
			}
			return $coupon;
		}
	}
	// goods button controller function
	function search() {
		if(isset($_POST["f"])){
			$limit = 24;
		}else
			$limit = 23;
		//导航按钮搜索功能
		$tit = $this->input->post ( 'name' );
		if ($this->input->post ( 'pageno' )) {
			$pageno = $this->input->post ( 'pageno' );
		} else {
			$pageno = 1;
		}
		$c = new TopClient ();
		$c->appkey = APPKEY;
		$c->secretKey = SECRETKEY;
		$req = new Coupon ();
		if ($_SESSION ['uid'] !="") {
			$req->setOuterCode ($_SESSION ['uid']);
		}else{
		$req->setOuterCode ($_COOKIE['uid']);
		}
		$req->setPid ( 17750613 );
		$req->setPageNo ( $pageno );
		$req->setPageSize ( $limit );
		//店铺类型 b商城店 c集市店 不设默认全部
		$req->setShopType("b");
		//排序类型 default(默认排序), price_desc(折扣价格从高到低), price_asc(折扣价格从低到高), credit_desc(信用等级从高到低), credit_asc(信用等级从低到高), commissionRate_desc(佣金比率从高到低), commissionRate_asc(佣金比率从低到高), volume_desc(成交量成高到低), volume_asc(成交量从低到高)
		$req->setSort ( "volume_desc" );
		$req->setKeyword ( $tit );
		$req->setFields ( "num_iid,title,volume,nick,price,item_location,click_url,pic_url,coupon_rate,coupon_price,coupon_start_time,coupon_end_time,commission_rate,commission,shop_type" );
		$resp = $c->execute ( $req );
		$res = $c->get_object_vars_final ( $resp );
		$val = @$res ['taobaoke_items'] ['taobaoke_item'];
		if (empty ( $res )) {
			$result ['msg'] = $this->_lang ['tbk_not_in'];
			$result ['error'] = 1;
		} else {
			$result ['html'] = "";
			foreach ( $val as $v ) {
				$result ['html'] .= "<div class='item items' >";
				$result ['html'] .= "<div class='tgms9 tiel'>";
				$result ['html'] .= "<a href=". $v['click_url'] . "target=_blank class=thickbox title=" . $v['title'] . ">" . $v['title'] . "</a></div>";
				$result ['html'] .= "<a href=" . $v['click_url'] . " target=_blank ><img width=260 src=" . $v['pic_url'] . "_60x60.jpg /></a>";
				$result ['html'] .= "<div class=pprice><span class=left>已售<em>" . $v['volume'] . "</em></span><span class=right>返利<em>". $v['commission'] . "</em></span></div>";
				$result ['html'] .= "<div class=tbk0><div class=tgms16><div class=deldiv><del>" . $v['price'] . "元</del></div>";
				$result ['html'] .= "<div class=spandiv><span>结束时间:" . $v['coupon_end_time']. "</span></div><div class=clear></div>";
				$result ['html'] .= "<a href=".$v['click_url']. "target=_blank ><span class=price>￥<em>" . $v['coupon_price']. "</em></span> <b class=btn></b></a>";
				$result ['html'] .= "<div class=clear></div></div></div></div>";
			}
			$result ['pageno'] = $pageno + 1;
			$result ['error'] = 0;
		}
		echo json_encode ( $result );
	}
	private function init($word = '', $page = 1) {
		//首页初始页面调用函数
		$c = new TopClient ();
		$c->appkey = APPKEY;
		$c->secretKey = SECRETKEY;
		$req = new Coupon ();
		$req->setPid ( 17750613 );
		$req->setPageNo ( 1 );

		$req->setPageSize ( 23 );
		if (isset ( $_SESSION ['uid'] )) {
			$req->setOuterCode ($_SESSION ['uid']);
		}
		$req->setShopType("b");
		$req->setKeyword ( $word );
		$req->setSort ( "volume_desc" );
		$req->setFields ( "num_iid,title,volume,nick,price,item_location,click_url,pic_url,coupon_rate,coupon_price,coupon_start_time,coupon_end_time,commission_rate,commission,shop_type" );
		$resp = $c->execute ( $req );

		$res = $c->get_object_vars_final ( $resp );
		$val = @$res ['taobaoke_items'] ['taobaoke_item'];
		return $val;
	}
	//判断用户是否已登入
	function is_load(){
		if($_SESSION['uid'] !=""){
			echo "1";
		}else{
			echo "0";
		}
	}
}

?>